<?php

namespace App\Models\Cruise;

use App\Models\BaseModel;
use App\Models\Common\FsCompanyModel;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Relations\HasOne;

class CruiseCheckTaskGroupModel extends BaseModel
{
    use KfUid;

    protected $table    = 'cruise_check_task_groups';
    protected $fillable = ['taskId', 'source', 'role', 'userId', 'relationCode', 'companyId', 'shopIds', 'beCruiseCheckCompanyIds'];

    const ROLE_USER    = 1;
    const ROLE_COMPANY = 2;
    const ROLE_TEXT    = [
        self::ROLE_USER    => '内部员工',
        self::ROLE_COMPANY => '第三方巡检',
    ];

    /**
     * source 数据来源
     */
    const SOURCE_DEFAULT = 0;  // 默认
    const SOURCE_IMPORT  = 1;  // 导入

    public function getShopIdsArrAttribute(): array
    {
        return json_decode($this->shopIds ?? "[]", true);
    }

    public function getBeCruiseCheckCompanyIdsArrAttribute(): array
    {
        return json_decode($this->beCruiseCheckCompanyIds ?? "[]", true);
    }

    /**
     * @return HasOne
     */
    public function fsCompanyRel(): HasOne
    {
        return $this->hasOne(FsCompanyModel::class, "departmentId", "companyId");
    }
}
